{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 《.NET/C#面试手册》\n",
    "\n",
    ".NET/C#⾯试题汇总系列：基础语法 \n",
    "\n",
    ".NET/C#⾯试题汇总系列：⾯向对象 \n",
    "\n",
    ".NET/C#⾯试题汇总系列：集合、异常、泛型、LINQ、委托、EF！ \n",
    "\n",
    ".NET/C#⾯试题汇总系列：多线程 \n",
    "\n",
    ".NET/C#⾯试题汇总系列：ASP.NET MVC \n",
    "\n",
    ".NET/C# ⾯试题汇总系列：ASP.NET Core \n",
    "\n",
    ".NET/C#⾯试题汇总系列：ADO.NET、XML、HTTP、AJAX、WebService \n",
    "\n",
    ".NET/C#⾯试题汇总系列：常⻅的算法 \n",
    "\n",
    ".NET/C#⾯试题汇总系列：数据库概念知识 \n",
    "\n",
    ".NET/C#⾯试题汇总系列：数据库SQL查询（附建表语句）\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# .NET/C#⾯试题汇总系列：基础语法\n",
    "\n",
    "##### 1. 字符串string str = null 和 string str =\"\" 和string str = string.Empty的区别？\n",
    "\n",
    "string.Empty相当于“” ，Empty是一个静态只读的字段。string str = \"\",初始化对象，并分配一个空的内存空间 string  str = null ,初始化对象，不会分配内存空间\n",
    "\n",
    "\n",
    "\n",
    "##### 2. byte b='a' ;byte c = 1 ;byte d = 'ab' ; byte e = '啊'; byte g  = 256;这些变量有哪些错误是错在哪里？\n",
    "\n",
    "本题考查的是数据类型能承载的数据的大小。\n",
    "1byte = 8bit ,一个汉字=2byte,一个英文= 1byte = 8bit\n",
    "所以bc 是对的 ，edg是错的。'a' 是char类型，a错误\n",
    "java byte 取值范围是-128-127， 而C#一个byte是0-255\n",
    " \n",
    "\n",
    " ##### 3.string和StringBuilder的区别,两者性能的⽐较\n",
    "\n",
    " 都是引用类型，分配再堆上\n",
    " StringBuilder默认容量是16，可以允许扩充它所封装的字符串中字符的数量。每个StringBuffer对象都有一定的缓冲区容量，当字符串的大小没有超过容量时，不会分配新的容量，当字符串大小超过容量时，会自动增加容量。\n",
    "\n",
    " 对于简单的字符串连接操作，在性能比较少的情况下，过度滥用stringBuilder会导致性能的浪费而非节约，只有大量无法预知次数的字符串才考虑使用stringbuilder的使用。从最后分析可以看出如果是相对较少的字符串拼接根本看不出太大区别。\n",
    "\n",
    " Stringbuilder的使用，最好制定合适的容量值，否则优于默认值容量不足而频繁的进行内存分配操作。是不妥的实现方式。\n",
    "\n",
    " [参考链接](https://www.cnblogs.com/haofuqi/p/4826262.html \"String和StringBuilder的深入解析\")\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 4.什么是扩展方法？\n",
    "\n",
    "一句话解释，扩展方法使你能够向现有类型“添加方法” ，无需修改类型\n",
    "条件：按扩展方法必须满足的条件 \n",
    "    1.必须要静态类中的静态方法 \n",
    "    2.第一个参数的类型是要拓展的类型并且需要添加this关键字以标识为拓展方法\n",
    "    \n",
    "建议：通常，只在不得已的情况下才实现扩展方法，并谨慎的实现\n",
    "\n",
    "使用:不能通过雷明调用，直接使用类型来调用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "##### 5.byte a =255;a+=5;a的值是多少？\n",
    "\n",
    "byte的取值范围是-2的8次⽅⾄2的8次⽅-1，-256⾄258，a+=1时，a的值时0，a+=5时，a的值是0，所 以a+=5时，值是4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "vscode": {
     "languageId": "csharp"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a的值为4\n"
     ]
    }
   ],
   "source": [
    "byte a = 255;\n",
    "a+=5;\n",
    "Console.WriteLine(\"a的值为{0}\",a);      "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 6.什么是装箱和拆箱?\n",
    "\n",
    "装箱就是隐式地将⼀个值类型转换成引⽤类型，如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "vscode": {
     "languageId": "csharp"
    }
   },
   "outputs": [],
   "source": [
    " int i=0;\n",
    " System.Object obj = i;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "拆箱就是将引用类型转成值类型，如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "vscode": {
     "languageId": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "int i=0;\n",
    "System.Object obj = i;\n",
    "int j = (int)obj; //将obj拆箱"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 7.值类型和引用类型的区别\n",
    "\n",
    "值类型变量是直接包含值。将一个值类型赋给另一个值类型变量，是复制包含的值，默认是0。\n",
    "\n",
    "引用类型变量的赋值只复制对对象的引用，而不复制对象本身，默认值是null。\n",
    "\n",
    "值类型有整形、浮点型、bool、枚举\n",
    "\n",
    "应用类型有class、delegate、Object、string\n",
    "\n",
    "值类型储存在栈中，引用类型储存在堆中"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 8.new关键字的作用？\n",
    "\n",
    "运算符：创建对象实例\n",
    "\n",
    "修饰符：在派生类定义一个重名的方法，隐藏掉基类方法\n",
    "\n",
    "约束：泛型约束定义，约束可使用的泛型类型，如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "vscode": {
     "languageId": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "public class ItemFactory<T> where T : IComparable, new() \n",
    "{ \n",
    "\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 9.int?和int 有什么区别？\n",
    "\n",
    "int? 可为空类型，默认值可以是null\n",
    "\n",
    "int默认值是0\n",
    "\n",
    "int?是通过int装箱为引用类型实现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 10.C#中委托是什么？\n",
    "\n",
    "一句话解释就是：将方法当作参数传入另一个方法的参数。\n",
    ".net中有很多常见的委托如：Func、Action\n",
    "\n",
    "作用：提高方法的拓展性"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 11.最有效的方法算数2乘以8等于几？\n",
    "\n",
    "位运算是最快，使⽤的是位运算 逻辑左位移<<。 ⽅法是2<<3相当于0000 0000 0000 0010 （2的16位 int⼆进制）左移三位就是 0000 0000 0001 0000（16的⼆进制）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "csharp"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "file_extension": ".cs",
   "mimetype": "text/x-csharp",
   "name": "C#",
   "pygments_lexer": "csharp",
   "version": "10.0"
  },
  "vscode": {
   "interpreter": {
    "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
